import React, { Component } from 'react'
import PropTypes from 'prop-types'

import Item from '../Item/Item'

import './List.css'

export default class List extends Component {
  
  // 对接收的属性进行类型检查
  static propTypes = {
    todos: PropTypes.array.isRequired,
    changeTodo: PropTypes.func.isRequired,
    deleteTodo: PropTypes.func.isRequired
  }
  render () {
    const { todos } = this.props
    return (
      <ul className='todo-main'>
        {todos.map(todo => {
          return (
            <Item
              changeTodo={this.props.changeTodo}
              deleteTodo={this.props.deleteTodo}
              key={todo.id}
              {...todo}
            />
          )
        })}
      </ul>
    )
  }
}
